<template>
  <el-table :data="bannerArr">
    <el-table-column label="编号" type="index"></el-table-column>
    <el-table-column label="轮播图">
      <template slot-scope="scope">
        <img :src="scope.row.imgUrl" width="200">
      </template>
    </el-table-column>
    <el-table-column label="创建时间" prop="createTime"></el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button type="danger" @click="handleDelete(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  name: "AdminBannerView",
  data() {
    return {
      bannerArr:[],
    }
  },
  methods: {
    handleDelete(i,banner) {
      if (confirm("您确认删除此轮播图吗?")){
        this.axios.post(this.BASE_URL+'/v1/banners/'+banner.id+"/delete")
        .then((response)=>{
          if (response.data.code==1){
            this.$message.success("删除成功!");
            this.bannerArr.splice(i,1);
          }
        })
      }
    }
  },
  mounted() {
    //请求轮播图数据
    this.axios.get(this.BASE_URL+'/v1/banners/admin').then((response)=>{
      if (response.data.code==1){
        this.bannerArr = response.data.data;
      }
    })
  }
}
</script>

<style scoped>

</style>